package com.example.thymeleafdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.security.PrivilegedAction;
import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName SessionController
 * @Description
 * @Author zhangsw
 * @Date 2020/12/2 17:25
 * @Version 1.0
 */
@Controller
public class SessionController {

    @GetMapping("sessionTest")
    public String sessionTest(HttpSession session, Model model) {
        session.setAttribute("username", "zhangsan");
        User user = new User();
        user.setAge(12);
        user.setPwd("666");
        user.setUsername("zhang");
        session.setAttribute("userInfo", user);
        session.setMaxInactiveInterval(60 * 5);
        model.addAttribute("flag", '1');
        return "session_ts";
    }

    public static void main(String[] args) {
//        Integer a = 11111111111;
        Set<String> set = new HashSet<>();
        Set<String> set2 = null;
        Set<String> set3 = new HashSet<>();
        set3.add("aaa");
        if (!CollectionUtils.isEmpty(set)) {
            System.err.println("set有数据");
        }
        if (!CollectionUtils.isEmpty(set2)) {
            System.err.println("set2有数据");
        }
        if (!CollectionUtils.isEmpty(set3)) {
            System.err.println("set3有数据");
        }
    }
}

class User {
    private String username;
    private String pwd;
    private Integer age;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
